#!/bin/sh

if [ ! -f data/scripts/update_version ]; then
	echo "this script must be run from project root"
	exit 1
fi

PREV_VERS=$(sed -n "s,\(Version: \)\(.*\),\2,p" libroxml.pc)

echo -n "previous version (detected=$PREV_VERS): "
read ANS
[ -z "$ANS" ] && PREV_VERS=$ANS
echo -n "new version: "
read ANS
if [ -z "$ANS" ]; then
	echo "version number is empty, abort."
	exit 1
fi
VERSION=$ANS

DATE=$(LANG=C date +"%a, %d %b %Y %X %z")

# update version number in required files:
# debian/rules 'version=VERSION'
sed -i "s,\(version=\).*,\1$VERSION," debian/rules

# libroxml.pc 'Version: VERSION'
sed -i "s,\(Version: \).*,\1$VERSION," libroxml.pc

# libroxml.spec 'version VERSION'
sed -i "s,\(version \).*,\1$VERSION," libroxml.spec

# doxy.cfg 'PROJECT_NUMBER         = VERSION'
sed -i "s,\(PROJECT_NUMBER.*= \).*,\1$VERSION," doxy.cfg

# man.cfg 'PROJECT_NUMBER         = VERSION'
sed -i "s,\(PROJECT_NUMBER.*= \).*,\1$VERSION," man.cfg

# CMakeLists.txt 'set (SOVERSION "2.0.2")'
sed -i "s,\(set (SOVERSION \"\).*\(\")\),\1$VERSION\2," CMakeLists.txt

# inc/roxml-doxy.h 'Lastest version is VERSION'
sed -i "s,\(Lastest version is \)[0-9]*\.[0-9]*\.[0-9]*\(:.*\),\1$VERSION\2," inc/roxml-doxy.h

# inc/roxml-doxy.h 'libroxml-VERSION.tar.gz'
sed -i "s,\(libroxml-\)[0-9]*\.[0-9]*\.[0-9]*\(.tar.gz\),\1$VERSION\2," inc/roxml-doxy.h

# debian/changelog
echo "libroxml ($VERSION-1) unstable; urgency=low" > .debian.changelog
echo "" >> .debian.changelog
echo " -- Name <mail@libroxml.net>  $DATE" >> .debian.changelog
echo "" >> .debian.changelog
cat debian/changelog >> .debian.changelog
mv .debian.changelog debian/changelog

vi debian/changelog

